package controller

import (
	"net/http"
	"webhook/services"

	"github.com/gin-gonic/gin"
)

func GitLabWebHook(ctx *gin.Context) {
	from := ctx.Param("from")
	key := ctx.Param("key")
	//event := ctx.GetHeader("X-GitLab-Event")
	gitlib_msg := make(map[string]any)
	if err := ctx.ShouldBind(&gitlib_msg); err != nil {
		ctx.Status(http.StatusBadRequest)
		return
	}
	result := services.GitLabWebHook(from, key, gitlib_msg)
	if result == 0 {
		ctx.Status(http.StatusBadRequest)
		return
	}
	ctx.Status(http.StatusOK)
}

func ApiHook(ctx *gin.Context) {
	from := ctx.Param("from")
	key := ctx.Param("key")
	content := ctx.Query("content")
	result := services.ApiHook(from, key, content)
	if result == 0 {
		ctx.Status(http.StatusBadRequest)
		return
	}
	ctx.Status(http.StatusOK)
}
